<template>
	<view class="container">
		<view  style="width: 100%;">
		<uni-section title="图" sub-title="" type="line">
			<image :src="'http://localhost:8090'+food.icon" style="width: 100%;height: 300rpx;" mode=""></image>
		</uni-section>
		<uni-section title="名称" sub-title="" type="line">
			<text>{{food.name}}</text>
		</uni-section>
		<uni-section title="类别" sub-title="" type="line">
			<text>{{food.type}}</text>
		</uni-section>
		<uni-section title="价格" sub-title="" type="line">
			<text>{{food.price}}元</text>
		</uni-section>
		<uni-section title="描述" sub-title="" type="line">
			<text>{{food.description}}</text>
		</uni-section>
		</view>
			<view style= "background-color: #ffffff; position: absolute;bottom: 0;width: 375px;height: 100rpx;display: flex;flex-direction: row; align-items: center;">
			<uni-easyinput  v-model="newcomment.comment" placeholder="请输入评论" style="background-color: #FFFFFF;padding-left: 10rpx;" />
			<button type="default" style="height: 75rpx;margin-right: 10rpx;font-size: 30rpx;" @click="addcomment">发表</button>
            </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				food: {},
				newcomment:{
					
				}
			}
		},
		methods: {
addcomment(){
  let y=new Date().getFullYear();
  let m=new Date().getMonth();
  let d=new Date().getDay();
   this.newcomment.postdate=y+"-"+m+'-'+d
if(this.newcomment.userid==""||this.newcomment.userid==null){
	uni.showToast({
		icon:"none",
		title:"请先登录"
	});
	return false
}

if(this.newcomment.comment==""||this.newcomment.comment==null){
	uni.showToast({
		icon:"none",
		title:"请输入评论"
	});
	return false
}

	uni.request({
		url: 'http://localhost:8090/foodapp/comment/addone',
		method: 'POST',
		data: this.newcomment,
		success: res => {
			console.log(this.newcomment);
			this.newcomment.comment=null
		},
		fail: () => {},
		complete: () => {}
	});
}
		},
		onLoad(e) {
			uni.request({
				url: 'http://localhost:8090/foodapp/food/findone',
				method: 'POST',
				data: {
					id: e.id
				},
				success: res => {
					if (res.data.success) {
					let userid=uni.getStorageSync("user").id
					
						this.food = res.data.data
						this.newcomment.foodid=this.food.id
						this.newcomment.userid=userid;
					}
				},
				fail: () => {},
				complete: () => {}
			});
		}
	}
</script>

<style>
</style>
